package org.grew.openEntity.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.grew.openEntity.po.logic.ProjectObj;
import org.grew.openEntity.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: todd
 * @Date: 2019/1/7 10:33
 * @Description:
 */
@Controller
@RequestMapping("project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @PostMapping(value = "create")
    public String createProject(@RequestParam String projectName){
        return "redirect:/project/createPage?code="+projectService.createProject(new ProjectObj(projectName));
    }

    @PostMapping(value = "findProjectByName",produces = "application/json")
    @ResponseBody
    public String findProjectByName(){
        List<ProjectObj> projects = projectService.getProjectALL();
        JSONArray proArr = JSONArray.parseArray(JSON.toJSONString(projects));
        return proArr.toJSONString();
    }

}
